package com.example.wujinapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wujinapi.dao.NoticsmessageDao;
import com.example.wujinapi.dao.NoticsmessageDao;
import com.example.wujinapi.entity.Noticsmessage;
import com.example.wujinapi.entity.Noticsmessage;
import com.example.wujinapi.service.NoticsmessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * (Noticsmessage)表服务实现类
 *
 * @author makejava
 * @since 2023-07-10 22:32:40
 */
@Service("noticsmessageService")
public class NoticsmessageServiceImpl extends ServiceImpl<NoticsmessageDao, Noticsmessage> implements NoticsmessageService {

    @Autowired
    private NoticsmessageDao noticsmessageDao;

    @Override
    public void addNoticsmessage(Noticsmessage noticsmessage) {
        Noticsmessage noticData=noticsmessageDao.selectOne(new QueryWrapper<Noticsmessage>().eq("newstitle", noticsmessage.getNewstitle()));
        if(noticData==null){ //为空才插入新用户
            noticsmessageDao.insert(noticsmessage);
        }
    }

    @Override
    public void deleteNoticsmessage(int noticId) {
        noticsmessageDao.delete(new QueryWrapper<Noticsmessage>().eq("id",noticId));
    }

    @Override
    public List<Map<String, Object>> getNoticsmessage(int pageNum, int pageSize) {
        Page<Noticsmessage> page = new Page<Noticsmessage> (pageNum,pageSize); //实现定义的接口
        List<Map<String,Object>> Datas=noticsmessageDao.selectPageVo(page);
        return Datas;
    }
}

